USE [INTERPUAN]
GO
/****** Object:  Table [dbo].[INTERBONUS_PUAN]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_PUAN](
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NOT NULL,
	[Puan] [decimal](18, 2) NULL,
	[ToplamTutar] [decimal](18, 2) NULL,
	[RiskLimiti] [decimal](18, 2) NULL,
	[RiskBakiyesi] [decimal](18, 2) NULL,
	[KrediLimiti] [decimal](18, 2) NULL,
	[KrediBakiyesi] [decimal](18, 2) NULL,
	[INTERBONUSPUANID] [int] IDENTITY(1,1) NOT NULL,
	[DATECREATED] [datetime] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
 CONSTRAINT [PK_PUAN] PRIMARY KEY CLUSTERED 
(
	[Cari_Kod] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PUAN] ON [dbo].[INTERBONUS_PUAN] 
(
	[Puan] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PUAN_1] ON [dbo].[INTERBONUS_PUAN] 
(
	[KrediBakiyesi] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[INTERBONUS_PROMOTION]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_PROMOTION](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Plu_No] [int] NULL,
	[Fiyat] [decimal](15, 4) NULL,
	[Flag] [bit] NULL,
	[Sube_Kodu] [nvarchar](20) COLLATE Turkish_CI_AS NULL,
	[Kasa_No] [smallint] NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NULL,
	[Tarih] [datetime] NULL,
	[Belge_Tipi] [tinyint] NULL,
	[Belge_No] [smallint] NULL,
	[DATECREATED] [datetime] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
 CONSTRAINT [PK_INTERBONUS_PROMOTION] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[INTERBONUS_OFFLINEMUKERRER]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_OFFLINEMUKERRER](
	[INTERBONUSOFFLINEMUKERRERID] [bigint] IDENTITY(1,1) NOT NULL,
	[ID] [decimal](38, 0) NULL,
	[Tarih] [datetime] NULL,
	[Belge_No] [smallint] NULL,
	[Belge_Tipi] [tinyint] NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NULL,
	[Puan] [decimal](18, 2) NULL,
	[ToplamTutar] [decimal](18, 2) NULL,
	[RiskBakiyesi] [decimal](18, 2) NULL,
	[KrediBakiyesi] [decimal](18, 2) NULL,
	[Kasa_No] [smallint] NULL,
	[Offline] [bit] NULL,
	[Sube_Kodu] [nvarchar](20) COLLATE Turkish_CI_AS NULL,
	[DATECREATED] [datetime] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
 CONSTRAINT [PK_INTERBONUS_OFFLINEMUKERRER] PRIMARY KEY CLUSTERED 
(
	[INTERBONUSOFFLINEMUKERRERID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[INTERBONUS_MAGAZA]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[INTERBONUS_MAGAZA](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Kodu] [varchar](50) COLLATE Turkish_CS_AS NOT NULL,
	[Adi] [varchar](50) COLLATE Turkish_CS_AS NOT NULL,
	[PosgenelYol] [varchar](50) COLLATE Turkish_CS_AS NOT NULL,
	[PoskonYol] [varchar](500) COLLATE Turkish_CS_AS NOT NULL,
	[KasaNolari] [varchar](50) COLLATE Turkish_CS_AS NOT NULL,
 CONSTRAINT [PK_INTERBONUS_MAGAZA] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[INTERBONUS_KULLANICI]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[INTERBONUS_KULLANICI](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Adi] [varchar](50) COLLATE Turkish_CI_AS NOT NULL,
	[Sifre] [varchar](50) COLLATE Turkish_CI_AS NOT NULL,
	[Admin] [bit] NOT NULL,
 CONSTRAINT [PK_INTERBONUS_KULLANICI] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[INTERBONUS_KONTOR]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_KONTOR](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Kart_Sifre] [nvarchar](20) COLLATE Turkish_CS_AS NULL,
	[Flag] [bit] NULL,
	[Sube_Kodu] [nvarchar](20) COLLATE Turkish_CI_AS NULL,
	[Kasa_No] [smallint] NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NULL,
	[Tarih] [datetime] NULL,
	[Belge_Tipi] [tinyint] NULL,
	[Belge_No] [smallint] NULL,
	[DATECREATED] [datetime] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
 CONSTRAINT [PK_INTERBONUS_KONTOR] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedDataType [dbo].[IDtam]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[IDtam] FROM [int] NOT NULL
GO
/****** Object:  UserDefinedDataType [dbo].[IDmini]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[IDmini] FROM [tinyint] NOT NULL
GO
/****** Object:  UserDefinedDataType [dbo].[IDkucuk]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[IDkucuk] FROM [smallint] NOT NULL
GO
/****** Object:  UserDefinedDataType [dbo].[IDbuyuk]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[IDbuyuk] FROM [bigint] NOT NULL
GO
/****** Object:  UserDefinedDataType [dbo].[evethayir]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[evethayir] FROM [bit] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[dvpara]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[dvpara] FROM [decimal](20, 6) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[dvfiyat]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[dvfiyat] FROM [decimal](20, 8) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[buyuksayi]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[buyuksayi] FROM [bigint] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[boyut]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[boyut] FROM [float] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[agirlik]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[agirlik] FROM [float] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[minisayi]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[minisayi] FROM [tinyint] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[kucuksayi]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[kucuksayi] FROM [smallint] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[karakter]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[karakter] FROM [nvarchar](1) NULL
GO
/****** Object:  Table [dbo].[INTERBONUS_VERSION]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_VERSION](
	[MAJOR] [int] NULL,
	[MINOR] [int] NULL,
	[BUILD] [int] NULL,
	[REVISION] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[INTERBONUS_PUANTANIM]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[INTERBONUS_PUANTANIM](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[No] [int] NOT NULL,
	[BaslangicTarihi] [datetime] NOT NULL,
	[BitisTarihi] [datetime] NOT NULL,
	[AlisverisToplami] [float] NOT NULL,
	[VerilecekPuan] [float] NOT NULL,
	[AlisverisPuani] [float] NOT NULL,
	[PuanParaKarsiligi] [float] NOT NULL,
	[PuanlaOdemeFisLimiti] [float] NOT NULL,
	[MusteriAraligi] [varchar](500) COLLATE Turkish_CS_AS NOT NULL,
	[OdemeTipi] [tinyint] NOT NULL,
 CONSTRAINT [PK_INTERBONUS_PUANTANIM] PRIMARY KEY CLUSTERED 
(
	[No] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  UserDefinedDataType [dbo].[tlpara]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[tlpara] FROM [decimal](20, 6) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[tlfiyat]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[tlfiyat] FROM [decimal](20, 8) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[tckimlik]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[tckimlik] FROM [nvarchar](11) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[tarih]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[tarih] FROM [datetime] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[tamsayi]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[tamsayi] FROM [int] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string50]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string50] FROM [nvarchar](50) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string5]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string5] FROM [nvarchar](5) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string4]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string4] FROM [nvarchar](4) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string30]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string30] FROM [nvarchar](30) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string3]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string3] FROM [nvarchar](3) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string255]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string255] FROM [nvarchar](255) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string200]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string200] FROM [nvarchar](200) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string20]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string20] FROM [nvarchar](20) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string2]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string2] FROM [nvarchar](2) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string150]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string150] FROM [nvarchar](150) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string15]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string15] FROM [nvarchar](15) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string100]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string100] FROM [nvarchar](100) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[string10]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[string10] FROM [nvarchar](10) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[sskno]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[sskno] FROM [nvarchar](13) NULL
GO
/****** Object:  UserDefinedDataType [dbo].[sayi]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[sayi] FROM [float] NULL
GO
/****** Object:  UserDefinedDataType [dbo].[plnkod]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[plnkod] FROM [nvarchar](30) NULL
GO
/****** Object:  Table [dbo].[INTERBONUS_CARI]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[INTERBONUS_CARI](
	[ID] [int] NOT NULL,
	[Kodu] [varchar](50) COLLATE Turkish_CS_AS NOT NULL,
	[Adi] [varchar](150) COLLATE Turkish_CS_AS NOT NULL,
	[Adresi] [varchar](500) COLLATE Turkish_CS_AS NOT NULL,
	[VergiDairesi] [varchar](100) COLLATE Turkish_CS_AS NOT NULL,
	[VergiNumarasi] [varchar](100) COLLATE Turkish_CS_AS NOT NULL,
	[IndirimOrani] [int] NOT NULL,
	[FiyatNo] [int] NOT NULL,
 CONSTRAINT [PK_INTERBONUS_CARI] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  UserDefinedDataType [dbo].[yuzdeoran]    Script Date: 07/16/2012 22:07:54 ******/
CREATE TYPE [dbo].[yuzdeoran] FROM [decimal](8, 4) NULL
GO
/****** Object:  StoredProcedure [dbo].[P_READBONUS_V1_0_1_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_READBONUS_V1_0_1_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2) output,
	@ToplamTutar decimal(18,2) output, 
	@RiskLimiti decimal(18,2) output, 
	@RiskBakiyesi decimal(18,2) output, 
	@KrediLimiti decimal(18,2) output, 
	@KrediBakiyesi decimal(18,2) output
AS
BEGIN
	SET NOCOUNT ON;
	IF EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		BEGIN
			DECLARE @T TABLE([Puan] [decimal](18, 2) NULL,
							 [ToplamTutar] [decimal](18, 2) NULL,
							 [RiskLimiti] [decimal](18, 2) NULL,
							 [RiskBakiyesi] [decimal](18, 2) NULL,
							 [KrediLimiti] [decimal](18, 2) NULL,
							 [KrediBakiyesi] [decimal](18, 2) NULL);
			INSERT INTO @T SELECT Puan, ToplamTutar, RiskLimiti, RiskBakiyesi, KrediLimiti, KrediBakiyesi FROM INTERBONUS_PUAN WITH(NOLOCK) WHERE Cari_Kod=@Cari_Kod;
			SET @Puan = (SELECT Puan FROM @T);
			SET @ToplamTutar = (SELECT ToplamTutar FROM @T);
			SET @RiskLimiti = (SELECT RiskLimiti FROM @T);
			SET @RiskBakiyesi = (SELECT RiskBakiyesi FROM @T);
			SET @KrediLimiti = (SELECT KrediLimiti FROM @T);
			SET @KrediBakiyesi = (SELECT KrediBakiyesi FROM @T);
		END
	ELSE
		BEGIN
			SET @Puan = 0;
			SET @ToplamTutar = 0;
			SET @RiskLimiti = 0;
			SET @RiskBakiyesi = 0;
			SET @KrediLimiti = 0;
			SET @KrediBakiyesi = 0;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_READBONUS_V1_0_0_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_READBONUS_V1_0_0_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2) output,
	@ToplamTutar decimal(18,2) output, 
	@RiskLimiti decimal(18,2) output, 
	@KrediLimiti decimal(18,2) output, 
	@KrediBakiyesi decimal(18,2) output
AS
BEGIN
	SET NOCOUNT ON;
	IF EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		BEGIN
			DECLARE @T TABLE([Puan] [decimal](18, 2) NULL,
							 [ToplamTutar] [decimal](18, 2) NULL,
							 [RiskLimiti] [decimal](18, 2) NULL,
							 [KrediLimiti] [decimal](18, 2) NULL,
							 [KrediBakiyesi] [decimal](18, 2) NULL);
			INSERT INTO @T SELECT Puan, ToplamTutar, RiskLimiti, KrediLimiti, KrediBakiyesi FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod;
			SET @Puan = (SELECT Puan FROM @T);
			SET @ToplamTutar = (SELECT ToplamTutar FROM @T);
			SET @RiskLimiti = (SELECT RiskLimiti FROM @T);
			SET @KrediLimiti = (SELECT KrediLimiti FROM @T);
			SET @KrediBakiyesi = (SELECT KrediBakiyesi FROM @T);
		END
	ELSE
		BEGIN
			SET @Puan = 0;
			SET @ToplamTutar = 0;
			SET @RiskLimiti = 0;
			SET @KrediLimiti = 0;
			SET @KrediBakiyesi = 0;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_INCREASEBONUS_V1_0_0_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_INCREASEBONUS_V1_0_0_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2)
AS
BEGIN
	SET NOCOUNT ON;
	IF NOT EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		INSERT INTO INTERBONUS_PUAN (Cari_Kod,Puan,ToplamTutar,RiskLimiti,KrediLimiti,KrediBakiyesi) VALUES (@Cari_Kod,0,0,0,0,0);
	UPDATE INTERBONUS_PUAN SET 
		Puan=Puan+@Puan, 
		ToplamTutar=ToplamTutar+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod
END
GO
/****** Object:  Table [dbo].[INTERBONUS_BAKIYEHAREKET]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_BAKIYEHAREKET](
	[INTERBONUSBAKIYEHAREKETID] [bigint] IDENTITY(1,1) NOT NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NOT NULL,
	[SERVERCOMPANYID] [smallint] NULL,
	[Eski_RiskLimiti] [decimal](18, 2) NULL,
	[Yeni_RiskLimiti] [decimal](18, 2) NULL,
	[Eski_RiskBakiyesi] [decimal](18, 2) NULL,
	[Yeni_RiskBakiyesi] [decimal](18, 2) NULL,
	[Eski_KrediLimiti] [decimal](18, 2) NULL,
	[Yeni_KrediLimiti] [decimal](18, 2) NULL,
	[Eski_KrediBakiyesi] [decimal](18, 2) NULL,
	[Yeni_KrediBakiyesi] [decimal](18, 2) NULL,
	[DATECREATED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
 CONSTRAINT [PK_BAKIYEHAREKET] PRIMARY KEY CLUSTERED 
(
	[INTERBONUSBAKIYEHAREKETID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASECCBALANCE_V1_0_0_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_DECREASECCBALANCE_V1_0_0_0]
	@Cari_Kod nvarchar(20),
	@Kredi decimal(18,2),
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE INTERBONUS_PUAN SET 
		KrediBakiyesi=KrediBakiyesi-@Kredi 
	WHERE Cari_Kod=@Cari_Kod AND KrediBakiyesi >= @Kredi;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  Table [dbo].[INTERBONUS_PUANHAREKET]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_PUANHAREKET](
	[ID] [decimal](38, 0) IDENTITY(1,1) NOT NULL,
	[Tarih] [datetime] NULL,
	[Belge_No] [smallint] NULL,
	[Belge_Tipi] [tinyint] NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NOT NULL,
	[Puan] [decimal](18, 2) NULL,
	[ToplamTutar] [decimal](18, 2) NULL,
	[RiskBakiyesi] [decimal](18, 2) NULL,
	[KrediBakiyesi] [decimal](18, 2) NULL,
	[Kasa_No] [smallint] NULL,
	[Offline] [bit] NULL,
	[Sube_Kodu] [nvarchar](20) COLLATE Turkish_CI_AS NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
	[DATECREATED] [datetime] NULL,
 CONSTRAINT [PK_PUANHAREKET] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_INTERBONUS_PUANHAREKET_Cari_Kod_Tarih_Belge_Tipi] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Cari_Kod] ASC,
	[Tarih] ASC,
	[Belge_Tipi] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_INTERBONUS_PUANHAREKET_Cari_Kod_Tarih_Belge_Tipi_Puan_ID] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Cari_Kod] ASC,
	[Tarih] ASC,
	[Belge_Tipi] ASC,
	[Puan] ASC,
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_INTERBONUS_PUANHAREKET_Puan_Cari_Kod_ID_Tarih_Belge_Tipi] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Puan] ASC,
	[Cari_Kod] ASC,
	[ID] ASC,
	[Tarih] ASC,
	[Belge_Tipi] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_INTERBONUS_PUANHAREKET_Tarih_Belge_Tipi_ID_Cari_Kod_Puan] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Tarih] ASC,
	[Belge_Tipi] ASC,
	[ID] ASC,
	[Cari_Kod] ASC,
	[Puan] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PH_Offline_ID_Tarih_Cari_Kod_Kasa_No_Belge_No_1] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Offline] ASC,
	[ID] ASC,
	[Tarih] ASC,
	[Cari_Kod] ASC,
	[Kasa_No] ASC,
	[Belge_No] ASC
)
INCLUDE ( [Belge_Tipi],
[Puan],
[ToplamTutar],
[RiskBakiyesi],
[KrediBakiyesi],
[Sube_Kodu],
[DATEMODIFIED],
[SESSIONIDCREATED],
[SESSIONIDMODIFIED],
[DATECREATED]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PH_Offline_ID_Tarih_Cari_Kod_Kasa_No_Belge_No_2] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Offline] ASC,
	[ID] ASC,
	[Tarih] ASC,
	[Cari_Kod] ASC,
	[Kasa_No] ASC,
	[Belge_No] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PH_Tarih_Cari_Kod_Kasa_No_Belge_No_ID] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Tarih] ASC,
	[Cari_Kod] ASC,
	[Kasa_No] ASC,
	[Belge_No] ASC,
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PUANHAREKET] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Cari_Kod] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PUANHAREKET_1] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Tarih] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_PUANHAREKET_2] ON [dbo].[INTERBONUS_PUANHAREKET] 
(
	[Belge_Tipi] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASEBONUS_V1_0_0_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_DECREASEBONUS_V1_0_0_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	UPDATE INTERBONUS_PUAN SET 
		Puan=Puan-@Puan, 
		ToplamTutar=ToplamTutar+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod AND Puan >= @Puan;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_6_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_6_0]
	@Plu_No int output,
	@Fiyat Decimal(15,4) output,
	@Server_Time Datetime Output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @Tmp_Cari_Kod nvarchar(20);
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	SET @Found=0;
	SET @Dongu=0;
	WHILE EXISTS (SELECT * FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE Flag=0)
		BEGIN
			IF NOT (@Sube_Kodu IS NULL OR @Sube_Kodu='')
			SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 AND Sube_Kodu=@Sube_Kodu ORDER BY ID);
			ELSE
			SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 ORDER BY ID);
			UPDATE INTERBONUS_PROMOTION SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
			IF @@Rowcount=1
				BEGIN	
					SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_PROMOTION WITH (NOLOCK) WHERE Flag=1 and ID=@ID);
					IF @@Error=1222 CONTINUE;
					SET @Dongu=0;
					IF @Tmp_Cari_Kod=@Cari_Kod
						BEGIN
						  SET @Server_Time=GetDate();			
						  SET @Plu_No = (SELECT Plu_No FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Fiyat = (SELECT Fiyat FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Found=1;
						  BREAK;
						END
					ELSE
						BEGIN
							BREAK;
						END
				END
			ELSE
				BEGIN
					SET @Dongu=@Dongu + 1
					IF @Dongu>100 
						BEGIN
							BREAK;
						END
					CONTINUE;
				END
		END
	IF @Found=0
		BEGIN
			SET @Plu_No = 0;
			SET @Fiyat = 0;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_5_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_5_0]
	@Plu_No int output,
	@Fiyat Decimal(15,4) output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @Tmp_Cari_Kod nvarchar(20);
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	SET @Found=0;
	SET @Dongu=0;
	WHILE EXISTS (SELECT * FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE Flag=0)
		BEGIN
			IF NOT (@Sube_Kodu IS NULL OR @Sube_Kodu='')
				SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 AND Sube_Kodu=@Sube_Kodu ORDER BY ID);
			ELSE
				SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 ORDER BY ID);
			UPDATE INTERBONUS_PROMOTION SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
			IF @@Rowcount=1
				BEGIN	
					SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_KONTOR WHERE Flag=1 and ID=@ID);
					IF @@Error=1222 CONTINUE;
					SET @Dongu=0;
					IF @Tmp_Cari_Kod=@Cari_Kod
						BEGIN			
						  SET @Plu_No = (SELECT Plu_No FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Fiyat = (SELECT Fiyat FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Found=1;
						  BREAK;
						END
					ELSE
						BEGIN
							BREAK;
						END
				END
			ELSE
				BEGIN
					SET @Dongu=@Dongu + 1
					IF @Dongu>100 
						BEGIN
							BREAK;
						END
					CONTINUE;
				END
		END
	IF @Found=0
		BEGIN
			SET @Plu_No = 0;
			SET @Fiyat = 0;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_4_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEPROMOTIONITEM_V1_0_4_0]
	@Plu_No int output,
	@Fiyat Decimal(15,4) output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @Tmp_Cari_Kod nvarchar(20);
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	SET @Found=0;
	SET @Dongu=0;
	WHILE EXISTS (SELECT * FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE Flag=0)
		BEGIN
			IF NOT (@Sube_Kodu IS NULL OR @Sube_Kodu='')
				SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 AND Sube_Kodu=@Sube_Kodu ORDER BY ID);
			ELSE 
				SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_PROMOTION WITH(UPDLOCK) WHERE Flag=0 ORDER BY ID);
			UPDATE INTERBONUS_PROMOTION SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
			IF @@Rowcount=1
				BEGIN	
					SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_KONTOR WHERE Flag=1 and ID=@ID);
					IF @@Error=1222 CONTINUE;
					SET @Dongu=0;
					IF @Tmp_Cari_Kod=@Cari_Kod
						BEGIN			
						  SET @Plu_No = (SELECT Plu_No FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Fiyat = (SELECT Fiyat FROM INTERBONUS_PROMOTION WITH(NOLOCK) WHERE ID=@ID);
						  SET @Found=1;
						  BREAK;
						END
					ELSE
						BEGIN
							BREAK;
						END
				END
			ELSE
				BEGIN
					SET @Dongu=@Dongu + 1
					IF @Dongu>100 
						BEGIN
							BREAK;
						END
					CONTINUE;
				END
		END
	IF @Found=0
		BEGIN
			SET @Plu_No = 0;
			SET @Fiyat = 0;
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEGSMITEM_V1_0_6_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEGSMITEM_V1_0_6_0]
	@Verilen_Adet tinyint output, 
	@Kart_Sifre nvarchar(4000) output,
	@Server_Time Datetime Output,
	@Istenen_Adet tinyint ,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	DECLARE @Sifre_Var bit;
	DECLARE @Tmp_Cari_Kod nvarchar(20);
	SET @Found=0;
	SET @Dongu=0;
	SET @Verilen_Adet=0;
	SET @Sifre_Var=0;
	SET @Kart_Sifre='';
	if @Istenen_Adet >190
		BEGIN
			SET @Istenen_Adet=190; -- Bir seferde 4000/21=190 Adet verebilir.
		END
	WHILE @Verilen_Adet<@Istenen_Adet
		BEGIN
			SET @Sifre_Var=0;
			WHILE EXISTS (SELECT * FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE Flag=0)
				BEGIN
					SET @Sifre_Var=1;
					SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_KONTOR WITH(UPDLOCK) WHERE Flag=0 Order By ID);
					UPDATE INTERBONUS_KONTOR SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
					IF @@RowCount=1
						BEGIN
							SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_KONTOR  WHERE Flag=1 and ID=@ID);
							IF @@ERROR=1222 CONTINUE;
							SET @Dongu=0;
							IF @Tmp_Cari_Kod=@Cari_Kod
								BEGIN
									IF @Verilen_Adet=0 SET @Server_Time=GetDate();
									SET @Kart_Sifre = @Kart_Sifre + (SELECT Kart_Sifre FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE ID=@ID)+CHAR(13);
									SET @Found=1;
									SET @Verilen_Adet= @Verilen_Adet+1;
									BREAK;
								END
							ELSE
								BEGIN
									BREAK;
								END
						END
					ELSE
						BEGIN
							SET @Dongu=@Dongu + 1
							IF @Dongu>100 
								BEGIN
									BREAK;
								END
							CONTINUE;
						END
				END
			if @Sifre_Var=0 
				BEGIN
					BREAK;
				END
		END		
	IF @Found=0
		BEGIN
			SET @Kart_Sifre = '';
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEGSMITEM_V1_0_5_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEGSMITEM_V1_0_5_0]
	@Verilen_Adet tinyint output, 
	@Kart_Sifre nvarchar(4000) output,
	@Istenen_Adet tinyint ,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	DECLARE @Sifre_Var bit;
	DECLARE @Tmp_Cari_Kod nvarchar(20);
	SET @Found=0;
	SET @Dongu=0;
	SET @Verilen_Adet=0;
	SET @Sifre_Var=0;
	SET @Kart_Sifre='';
	if @Istenen_Adet >190
		BEGIN
			SET @Istenen_Adet=190; -- Bir seferde 4000/21=190 Adet verebilir.
		END
	WHILE @Verilen_Adet<@Istenen_Adet
		BEGIN
			SET @Sifre_Var=0;
			WHILE EXISTS (SELECT * FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE Flag=0)
				BEGIN
					SET @Sifre_Var=1;
					SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_KONTOR WITH(UPDLOCK) WHERE Flag=0 Order By ID);
					UPDATE INTERBONUS_KONTOR SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
					IF @@RowCount=1
						BEGIN
							SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_KONTOR  WHERE Flag=1 and ID=@ID);
							IF @@ERROR=1222 CONTINUE;
							SET @Dongu=0;
							IF @Tmp_Cari_Kod=@Cari_Kod
								BEGIN
									SET @Kart_Sifre = @Kart_Sifre + (SELECT Kart_Sifre FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE ID=@ID)+CHAR(13);
									SET @Found=1;
									SET @Verilen_Adet= @Verilen_Adet+1;
									BREAK;
								END
							ELSE
								BEGIN
									BREAK;
								END
						END
					ELSE
						BEGIN
							SET @Dongu=@Dongu + 1
							IF @Dongu>100 
								BEGIN
									BREAK;
								END
							CONTINUE;
						END
				END
			if @Sifre_Var=0 
				BEGIN
					BREAK;
				END
		END		
	IF @Found=0
		BEGIN
			SET @Kart_Sifre = '';
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEGSMITEM_V1_0_4_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEGSMITEM_V1_0_4_0]
	@Kart_Sifre nvarchar(20) output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint,
	@Cari_Kod nvarchar(20),
	@Tarih Datetime,
	@Belge_Tipi tinyint,
	@Belge_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET LOCK_TIMEOUT 200;
	DECLARE @Found tinyint;
	DECLARE @ID bigint;
	DECLARE @Dongu tinyint;
	DECLARE @Tmp_Cari_Kod nvarchar(20);	
	SET @Found=0;
	SET @Dongu=0;
	WHILE EXISTS (SELECT * FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE Flag=0)
		BEGIN
			SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_KONTOR WITH(UPDLOCK) WHERE Flag=0 ORDER BY ID);
			UPDATE INTERBONUS_KONTOR SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No, Cari_Kod=@Cari_Kod, Tarih=@Tarih, Belge_Tipi=@Belge_Tipi, Belge_No=@Belge_No WHERE ID=@ID AND Flag=0;
			IF @@RowCount=1
				BEGIN
					SET @Dongu=0;
					SET @Tmp_Cari_Kod = (SELECT Cari_Kod FROM INTERBONUS_KONTOR WHERE Flag=1 and ID=@ID);
					IF @@ERROR=1222 CONTINUE;
					IF @Tmp_Cari_Kod=@Cari_Kod
						BEGIN			
							SET @Kart_Sifre = (SELECT Kart_Sifre FROM INTERBONUS_KONTOR WITH(NOLOCK) WHERE ID=@ID);
							SET @Found=1;
							BREAK;
						END
					ELSE
						BEGIN
							BREAK;
						END
				END
			ELSE
				BEGIN
					SET @Dongu=@Dongu + 1
					IF @Dongu>100 
						BEGIN
							BREAK;
						END
					CONTINUE;
				END
		END
	IF @Found=0
		BEGIN
			SET @Kart_Sifre = '';
		END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMEGSMITEM_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMEGSMITEM_V1_0_3_0]
	@Kart_Sifre nvarchar(20) output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	SET @Kart_Sifre = '';
	IF EXISTS (SELECT * FROM INTERBONUS_KONTOR WHERE Flag=0)
		BEGIN
			DECLARE @ID bigint;
			SET @ID = (SELECT TOP 1 ID FROM INTERBONUS_KONTOR WITH (UPDLOCK) WHERE Flag=0);
			UPDATE INTERBONUS_KONTOR SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No WHERE ID=@ID and Flag=0;
			if @@Rowcount=1
				BEGIN
				    SET @Kart_Sifre = (SELECT Kart_Sifre FROM INTERBONUS_KONTOR WHERE ID=@ID);
				END;
		END
	ELSE
		BEGIN
			SET @Kart_Sifre = '';
		END
END
GO
/****** Object:  Table [dbo].[INTERBONUS_INDIRIMCEK]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_INDIRIMCEK](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[Cek_No] [nvarchar](16) COLLATE Turkish_CS_AS NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NOT NULL,
	[Tutar] [decimal](18, 2) NULL,
	[Puan] [decimal](18, 2) NULL,
	[Baslangic] [datetime] NULL,
	[Bitis] [datetime] NULL,
	[Flag] [bit] NULL,
	[Sube_Kodu] [nvarchar](20) COLLATE Turkish_CI_AS NULL,
	[Kasa_No] [smallint] NULL,
	[Musteri_Flag] [bit] NULL,
	[Belge_Tutar] [decimal](18, 2) NULL,
	[DATECREATED] [datetime] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
 CONSTRAINT [PK_INTERBONUS_INDIRIMCEK] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_INTERBONUS_INDIRIMCEK] UNIQUE NONCLUSTERED 
(
	[Cek_No] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_INTERBONUS_INDIRIMCEK_1] ON [dbo].[INTERBONUS_INDIRIMCEK] 
(
	[Cari_Kod] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[INTERBONUS_HEDIYEHAREKET]    Script Date: 07/16/2012 22:07:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[INTERBONUS_HEDIYEHAREKET](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Tarih] [datetime] NULL,
	[Cari_Kod] [nvarchar](20) COLLATE Turkish_CS_AS NOT NULL,
	[Info] [nvarchar](30) COLLATE Turkish_CS_AS NULL,
	[Birim_Puan] [decimal](18, 2) NULL,
	[Adet] [decimal](7, 3) NULL,
	[Puan] [decimal](18, 2) NULL,
	[INTERBONUSHEDIYEID] [int] NULL,
	[DATEMODIFIED] [datetime] NULL,
	[SESSIONIDCREATED] [bigint] NULL,
	[SESSIONIDMODIFIED] [bigint] NULL,
	[DATECREATED] [datetime] NULL,
 CONSTRAINT [PK_HEDIYEHAREKET] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_HEDIYEHAREKET] ON [dbo].[INTERBONUS_HEDIYEHAREKET] 
(
	[Cari_Kod] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_HEDIYEHAREKET_1] ON [dbo].[INTERBONUS_HEDIYEHAREKET] 
(
	[Tarih] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASEBONUS_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[P_DECREASEBONUS_V1_0_3_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Sube_Kodu nvarchar(20),
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No, Belge_Tipi, Cari_Kod, Puan, ToplamTutar, RiskBakiyesi, KrediBakiyesi, Kasa_No, Sube_Kodu) 
					VALUES (@Belge_No, @Belge_Tipi, @Cari_Kod, -@Puan, @ToplamTutar, 0, 0, @Kasa_No, @Sube_Kodu);
	UPDATE INTERBONUS_PUAN SET 
		Puan=ISNULL(Puan,0)-@Puan, 
		ToplamTutar=ISNULL(ToplamTutar,0)+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod AND Puan >= @Puan;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASEBONUS_V1_0_1_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_DECREASEBONUS_V1_0_1_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar, RiskBakiyesi, KrediBakiyesi,Kasa_No) 
								VALUES (@Belge_No,@Belge_Tipi,@Cari_Kod,-@Puan,@ToplamTutar,0,0,@Kasa_No);
	UPDATE INTERBONUS_PUAN SET 
		Puan=Puan-@Puan, 
		ToplamTutar=ToplamTutar+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod AND Puan >= @Puan;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASECCBALANCE_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE  [dbo].[P_DECREASECCBALANCE_V1_0_3_0]
	@Cari_Kod nvarchar(20),
	@Kredi decimal(18,2),
	@Risk decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Sube_Kodu nvarchar(20),
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No, Belge_Tipi, Cari_Kod, Puan, ToplamTutar, RiskBakiyesi, KrediBakiyesi, Kasa_No, Sube_Kodu) 
					VALUES (@Belge_No, @Belge_Tipi, @Cari_Kod, 0, 0, -@Risk, -@Kredi, @Kasa_No, @Sube_Kodu);
	UPDATE INTERBONUS_PUAN SET 
		RiskBakiyesi=ISNULL(RiskBakiyesi,0)-@Risk, 
		KrediBakiyesi=ISNULL(KrediBakiyesi,0)-@Kredi 
	WHERE Cari_Kod=@Cari_Kod AND KrediBakiyesi >= @Kredi AND RiskBakiyesi >= @Risk;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  StoredProcedure [dbo].[P_DECREASECCBALANCE_V1_0_1_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_DECREASECCBALANCE_V1_0_1_0]
	@Cari_Kod nvarchar(20),
	@Kredi decimal(18,2),
	@Risk decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No) 
								VALUES (@Belge_No,@Belge_Tipi,@Cari_Kod,0,0,-@Risk,-@Kredi,@Kasa_No);
	UPDATE INTERBONUS_PUAN SET 
		RiskBakiyesi=RiskBakiyesi-@Risk, 
		KrediBakiyesi=KrediBakiyesi-@Kredi 
	WHERE Cari_Kod=@Cari_Kod AND KrediBakiyesi >= @Kredi AND RiskBakiyesi >= @Risk;
	SET @Counter = @@ROWCOUNT;
END
GO
/****** Object:  StoredProcedure [dbo].[P_INCREASEOFFBNS_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_INCREASEOFFBNS_V1_0_3_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Tarih datetime,
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Sube_Kodu nvarchar(20)
AS
BEGIN
	SET NOCOUNT ON;
	IF NOT EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		INSERT INTO INTERBONUS_PUAN(Cari_Kod,Puan,ToplamTutar,RiskLimiti,RiskBakiyesi,KrediLimiti,KrediBakiyesi) VALUES (@Cari_Kod,0,0,0,0,0,0); 
	INSERT INTO INTERBONUS_PUANHAREKET (Tarih, Belge_No, Belge_Tipi, Cari_Kod, Puan, ToplamTutar, RiskBakiyesi, KrediBakiyesi, Kasa_No, Offline, Sube_Kodu) 
					VALUES (@Tarih, @Belge_No, @Belge_Tipi, @Cari_Kod, @Puan, @ToplamTutar, 0, 0, @Kasa_No, 1, @Sube_Kodu);
	UPDATE INTERBONUS_PUAN SET 
		Puan=ISNULL(Puan,0)+@Puan, 
		ToplamTutar=ISNULL(ToplamTutar,0)+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod; 
END
GO
/****** Object:  StoredProcedure [dbo].[P_INCREASEOFFBNS_V1_0_2_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_INCREASEOFFBNS_V1_0_2_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Tarih datetime,
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	IF NOT EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		INSERT INTO INTERBONUS_PUAN(Cari_Kod,Puan,ToplamTutar,RiskLimiti,RiskBakiyesi,KrediLimiti,KrediBakiyesi) VALUES (@Cari_Kod,0,0,0,0,0,0); 
	INSERT INTO INTERBONUS_PUANHAREKET (Tarih, Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No, Offline) 
								VALUES (@Tarih, @Belge_No,@Belge_Tipi,@Cari_Kod,@Puan,@ToplamTutar,0,0,@Kasa_No, 1);
	UPDATE INTERBONUS_PUAN SET 
		Puan=Puan+@Puan, 
		ToplamTutar=ToplamTutar+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod; 
END
GO
/****** Object:  StoredProcedure [dbo].[P_INCREASEBONUS_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_INCREASEBONUS_V1_0_3_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint,
	@Sube_Kodu nvarchar(20)
AS
BEGIN
	SET NOCOUNT ON;
	IF NOT EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		INSERT INTO INTERBONUS_PUAN (Cari_Kod,Puan,ToplamTutar,RiskLimiti,RiskBakiyesi,KrediLimiti,KrediBakiyesi) VALUES (@Cari_Kod,0,0,0,0,0,0); 
		
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No, Sube_Kodu) 
					VALUES (@Belge_No,@Belge_Tipi,@Cari_Kod,@Puan,@ToplamTutar,0,0,@Kasa_No, @Sube_Kodu);

	UPDATE INTERBONUS_PUAN SET 
		Puan=ISNULL(Puan,0)+@Puan, 
		ToplamTutar=ISNULL(ToplamTutar,0)+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod; 
END
GO
/****** Object:  StoredProcedure [dbo].[P_INCREASEBONUS_V1_0_1_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_INCREASEBONUS_V1_0_1_0]
	@Cari_Kod nvarchar(20),
	@Puan decimal(18,2),
	@ToplamTutar decimal(18,2),
	@Belge_No smallint,
	@Belge_Tipi tinyint,
	@Kasa_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	IF NOT EXISTS(SELECT * FROM INTERBONUS_PUAN WHERE Cari_Kod=@Cari_Kod) 
		INSERT INTO INTERBONUS_PUAN (Cari_Kod,Puan,ToplamTutar,RiskLimiti,RiskBakiyesi,KrediLimiti,KrediBakiyesi) VALUES (@Cari_Kod,0,0,0,0,0,0); 
		
	INSERT INTO INTERBONUS_PUANHAREKET (Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No) 
								VALUES (@Belge_No,@Belge_Tipi,@Cari_Kod,@Puan,@ToplamTutar,0,0,@Kasa_No);
								
	UPDATE INTERBONUS_PUAN SET 
		Puan=Puan+@Puan, 
		ToplamTutar=ToplamTutar+@ToplamTutar 
	WHERE Cari_Kod=@Cari_Kod; 
END
GO
/****** Object:  Trigger [TR_INTERBONUS_INDIRIMCEKUPD]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_INDIRIMCEKUPD] ON [dbo].[INTERBONUS_INDIRIMCEK] 
FOR UPDATE
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM DELETED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan + @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,12,@Cari_Kod,@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM INSERTED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan - @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,12,@Cari_Kod,-@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  Trigger [TR_INTERBONUS_INDIRIMCEKINS]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_INDIRIMCEKINS] ON [dbo].[INTERBONUS_INDIRIMCEK] 
FOR INSERT
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM INSERTED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan - @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,12,@Cari_Kod,-@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  Trigger [TR_INTERBONUS_INDIRIMCEKDEL]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_INDIRIMCEKDEL] ON [dbo].[INTERBONUS_INDIRIMCEK] 
FOR DELETE
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM DELETED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan + @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,12,@Cari_Kod,@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  Trigger [TR_INTERBONUS_HEDIYEHRKTUPD]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_HEDIYEHRKTUPD] ON [dbo].[INTERBONUS_HEDIYEHAREKET] 
FOR UPDATE
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM DELETED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan + @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,11,@Cari_Kod,@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM INSERTED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
		UPDATE INTERBONUS_PUAN SET Puan = Puan - @Puan WHERE Cari_Kod=@Cari_Kod;
		INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,11,@Cari_Kod,-@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  Trigger [TR_INTERBONUS_HEDIYEHRKTINS]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_HEDIYEHRKTINS] ON [dbo].[INTERBONUS_HEDIYEHAREKET] 
FOR INSERT
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM INSERTED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
	UPDATE INTERBONUS_PUAN SET Puan = Puan - @Puan WHERE Cari_Kod=@Cari_Kod;
	INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,11,@Cari_Kod,-@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  Trigger [TR_INTERBONUS_HEDIYEHRKTDEL]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_INTERBONUS_HEDIYEHRKTDEL] ON [dbo].[INTERBONUS_HEDIYEHAREKET] 
FOR DELETE
AS 
BEGIN
	SET NOCOUNT ON;
	DECLARE @Cari_Kod nvarchar(20), @Puan decimal(18,2), @SESSIONID BIGINT;
	SELECT @Cari_Kod=Cari_Kod, @Puan=ISNULL(Puan,0),@SESSIONID=ISNULL(SESSIONIDMODIFIED,SESSIONIDCREATED) FROM DELETED;
	IF(@Cari_Kod IS NOT NULL)
	BEGIN
	UPDATE INTERBONUS_PUAN SET Puan = Puan + @Puan WHERE Cari_Kod=@Cari_Kod;
	INSERT INTO INTERBONUS_PUANHAREKET(Tarih,Belge_No,Belge_Tipi,Cari_Kod,Puan,ToplamTutar,RiskBakiyesi,KrediBakiyesi,Kasa_No,Offline,Sube_Kodu,SESSIONIDCREATED,DATECREATED) VALUES(GETDATE(),0,11,@Cari_Kod,@Puan,0,0,0,0,0,'',@SESSIONID,GETDATE())
	END	
END
GO
/****** Object:  StoredProcedure [dbo].[P_GIVEBACKCHEQUE_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_GIVEBACKCHEQUE_V1_0_3_0]
	@Cek_No nvarchar(16),
	@Counter tinyint output
AS
BEGIN
	SET NOCOUNT ON;
	BEGIN
		UPDATE INTERBONUS_INDIRIMCEK SET Flag=0, Sube_Kodu='', Kasa_No=NULL WHERE Cek_No=@Cek_No AND Flag=1;
		SET @Counter = @@ROWCOUNT;
	END
END
GO
/****** Object:  StoredProcedure [dbo].[P_READCHEQUE_V1_0_5_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_READCHEQUE_V1_0_5_0]
	@Cek_No nvarchar(16),
	@Cari_Kod nvarchar(20) output,
	@Tutar decimal(18,2) output,
	@Baslangic datetime output,
	@Bitis datetime output,
	@Flag bit output,
	@Musteri_Flag bit output,
	@Belge_Tutar decimal(18,2) output
AS
BEGIN
	SET NOCOUNT ON;
	BEGIN
		SELECT @Cari_Kod=Cari_Kod, @Tutar=Tutar, @Baslangic=Baslangic, @Bitis=Bitis, @Flag=Flag,@Musteri_Flag=Musteri_Flag,@Belge_Tutar=Belge_Tutar FROM INTERBONUS_INDIRIMCEK WITH(NOLOCK) WHERE Cek_No=@Cek_No;
	END
END
GO
/****** Object:  StoredProcedure [dbo].[P_READCHEQUE_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_READCHEQUE_V1_0_3_0]
	@Cek_No nvarchar(16),
	@Cari_Kod nvarchar(20) output,
	@Tutar decimal(18,2) output,
	@Baslangic datetime output,
	@Bitis datetime output,
	@Flag bit output
AS
BEGIN
	SET NOCOUNT ON;
	BEGIN
		SELECT @Cari_Kod=Cari_Kod, @Tutar=Tutar, @Baslangic=Baslangic, @Bitis=Bitis, @Flag=Flag FROM INTERBONUS_INDIRIMCEK WHERE Cek_No=@Cek_No;
	END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMECHEQUE_V1_0_5_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMECHEQUE_V1_0_5_0]
	@Cek_No nvarchar(16),
	@Counter tinyint output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	BEGIN
		DECLARE @ID bigint;
		SET @ID =ISNULL((SELECT TOP 1 ID FROM INTERBONUS_INDIRIMCEK WITH(NOLOCK) WHERE Cek_No=@Cek_No AND Flag=0),0);
		UPDATE INTERBONUS_INDIRIMCEK SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No WHERE ID=@ID AND Flag=0;
		SET @Counter = @@ROWCOUNT;
	END
END
GO
/****** Object:  StoredProcedure [dbo].[P_CONSUMECHEQUE_V1_0_3_0]    Script Date: 07/16/2012 22:07:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[P_CONSUMECHEQUE_V1_0_3_0]
	@Cek_No nvarchar(16),
	@Counter tinyint output,
	@Sube_Kodu nvarchar(20),
	@Kasa_No smallint
AS
BEGIN
	SET NOCOUNT ON;
	BEGIN
		DECLARE @ID bigint;
		SET @ID =ISNULL((SELECT TOP 1 ID FROM INTERBONUS_INDIRIMCEK WHERE Cek_No=@Cek_No AND Flag=0),0);
		UPDATE INTERBONUS_INDIRIMCEK SET Flag=1, Sube_Kodu=@Sube_Kodu, Kasa_No=@Kasa_No WHERE ID=@ID AND Flag=0;
		SET @Counter = @@ROWCOUNT;
	END
END
GO
/****** Object:  Default [DF_INTERBONUS_BAKIYEHAREKET_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_BAKIYEHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_BAKIYEHAREKET_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF_INTERBONUS_BAKIYEHAREKET_SESSIONIDCREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_BAKIYEHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_BAKIYEHAREKET_SESSIONIDCREATED]  DEFAULT ((0)) FOR [SESSIONIDCREATED]
GO
/****** Object:  Default [DF_INTERBONUS_HEDIYEHAREKET_Tarih]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_HEDIYEHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_HEDIYEHAREKET_Tarih]  DEFAULT (getdate()) FOR [Tarih]
GO
/****** Object:  Default [DF_INTERBONUS_HEDIYEHAREKET_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_HEDIYEHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_HEDIYEHAREKET_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF_INTERBONUS_INDIRIMCEK_Flag]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  CONSTRAINT [DF_INTERBONUS_INDIRIMCEK_Flag]  DEFAULT ((0)) FOR [Flag]
GO
/****** Object:  Default [DF__INTERBONU__Sube___1CF15040]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  DEFAULT ('') FOR [Sube_Kodu]
GO
/****** Object:  Default [DF__INTERBONU__Kasa___1DE57479]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  DEFAULT ((0)) FOR [Kasa_No]
GO
/****** Object:  Default [DF__INTERBONU__Muste__35BCFE0A]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  DEFAULT ((0)) FOR [Musteri_Flag]
GO
/****** Object:  Default [DF__INTERBONU__Belge__36B12243]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  DEFAULT ((0)) FOR [Belge_Tutar]
GO
/****** Object:  Default [DF_INTERBONUS_INDIRIMCEK_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] ADD  CONSTRAINT [DF_INTERBONUS_INDIRIMCEK_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF_INTERBONUS_KONTOR_Kart_Sifre]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_KONTOR] ADD  CONSTRAINT [DF_INTERBONUS_KONTOR_Kart_Sifre]  DEFAULT ('') FOR [Kart_Sifre]
GO
/****** Object:  Default [DF_INTERBONUS_KONTOR_Flag]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_KONTOR] ADD  CONSTRAINT [DF_INTERBONUS_KONTOR_Flag]  DEFAULT ((0)) FOR [Flag]
GO
/****** Object:  Default [DF__INTERBONU__Sube___164452B1]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_KONTOR] ADD  DEFAULT ('') FOR [Sube_Kodu]
GO
/****** Object:  Default [DF__INTERBONU__Kasa___173876EA]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_KONTOR] ADD  DEFAULT ((0)) FOR [Kasa_No]
GO
/****** Object:  Default [DF_INTERBONUS_KONTOR_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_KONTOR] ADD  CONSTRAINT [DF_INTERBONUS_KONTOR_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF__INTERBONU__Plu_N__300424B4]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  DEFAULT ((0)) FOR [Plu_No]
GO
/****** Object:  Default [DF_INTERBONUS_PROMOTION_Decimal]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  CONSTRAINT [DF_INTERBONUS_PROMOTION_Decimal]  DEFAULT ((0)) FOR [Fiyat]
GO
/****** Object:  Default [DF_INTERBONUS_PROMOTION_Flag]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  CONSTRAINT [DF_INTERBONUS_PROMOTION_Flag]  DEFAULT ((0)) FOR [Flag]
GO
/****** Object:  Default [DF__INTERBONU__Sube___32E0915F]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  DEFAULT ('') FOR [Sube_Kodu]
GO
/****** Object:  Default [DF__INTERBONU__Kasa___33D4B598]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  DEFAULT ((0)) FOR [Kasa_No]
GO
/****** Object:  Default [DF_INTERBONUS_PROMOTION_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PROMOTION] ADD  CONSTRAINT [DF_INTERBONUS_PROMOTION_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF_INTERBONUS_PUAN_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUAN] ADD  CONSTRAINT [DF_INTERBONUS_PUAN_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  Default [DF_INTERBONUS_PUANHAREKET_Tarih]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_PUANHAREKET_Tarih]  DEFAULT (getdate()) FOR [Tarih]
GO
/****** Object:  Default [DF_PUANHAREKET_Offline]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET] ADD  CONSTRAINT [DF_PUANHAREKET_Offline]  DEFAULT ((0)) FOR [Offline]
GO
/****** Object:  Default [DF__INTERBONU__Sube___286302EC]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET] ADD  DEFAULT ('') FOR [Sube_Kodu]
GO
/****** Object:  Default [DF_INTERBONUS_PUANHAREKET_DATECREATED]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET] ADD  CONSTRAINT [DF_INTERBONUS_PUANHAREKET_DATECREATED]  DEFAULT (getdate()) FOR [DATECREATED]
GO
/****** Object:  ForeignKey [FK_INTERBONUS_BAKIYEHAREKET_INTERBONUS_PUAN]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_BAKIYEHAREKET]  WITH CHECK ADD  CONSTRAINT [FK_INTERBONUS_BAKIYEHAREKET_INTERBONUS_PUAN] FOREIGN KEY([Cari_Kod])
REFERENCES [dbo].[INTERBONUS_PUAN] ([Cari_Kod])
GO
ALTER TABLE [dbo].[INTERBONUS_BAKIYEHAREKET] CHECK CONSTRAINT [FK_INTERBONUS_BAKIYEHAREKET_INTERBONUS_PUAN]
GO
/****** Object:  ForeignKey [FK_HEDIYEHAREKET_PUAN]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_HEDIYEHAREKET]  WITH CHECK ADD  CONSTRAINT [FK_HEDIYEHAREKET_PUAN] FOREIGN KEY([Cari_Kod])
REFERENCES [dbo].[INTERBONUS_PUAN] ([Cari_Kod])
GO
ALTER TABLE [dbo].[INTERBONUS_HEDIYEHAREKET] CHECK CONSTRAINT [FK_HEDIYEHAREKET_PUAN]
GO
/****** Object:  ForeignKey [FK_INTERBONUS_INDIRIMCEK_INTERBONUS_INDIRIMCEK]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK]  WITH CHECK ADD  CONSTRAINT [FK_INTERBONUS_INDIRIMCEK_INTERBONUS_INDIRIMCEK] FOREIGN KEY([Cari_Kod])
REFERENCES [dbo].[INTERBONUS_PUAN] ([Cari_Kod])
GO
ALTER TABLE [dbo].[INTERBONUS_INDIRIMCEK] CHECK CONSTRAINT [FK_INTERBONUS_INDIRIMCEK_INTERBONUS_INDIRIMCEK]
GO
/****** Object:  ForeignKey [FK_PUANHAREKET_PUAN]    Script Date: 07/16/2012 22:07:49 ******/
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET]  WITH CHECK ADD  CONSTRAINT [FK_PUANHAREKET_PUAN] FOREIGN KEY([Cari_Kod])
REFERENCES [dbo].[INTERBONUS_PUAN] ([Cari_Kod])
GO
ALTER TABLE [dbo].[INTERBONUS_PUANHAREKET] CHECK CONSTRAINT [FK_PUANHAREKET_PUAN]
GO
